from django import forms


# 前端样式

class BootStrap:
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # 循环找到所有的插件，添加了class="form-control"
        for name, field in self.fields.items():
            # if name == "password":
            #     continue
            if field.widget.attrs:
                field.widget.attrs["class"] = "form-control"
                field.widget.attrs["placeholder"] = field.label
            else:
                field.widget.attrs = {
                    "class ": "form-control",
                    "placeholder": field.label
                }


# ModelForm继承这个

class BootStrapModelForm(BootStrap, forms.ModelForm):
    pass
    """
        # def __init__(self, *args, **kwargs):
        #     super().__init__(*args, **kwargs)
        #
        #     # 循环找到所有的插件，添加了class="form-control"
        #     for name, field in self.fields.items():
        #         # if name == "password":
        #         #     continue
        #         if field.widget.attrs:
        #             field.widget.attrs["class"] = "form-control"
        #             field.widget.attrs["placeholder"] = field.label
        #         else:
        #             field.widget.attrs = {
        #                 "class ": "form-control",
        #                 "placeholder": field.label
        #             }
    """


# Form继承这个

class BootStrapForm(BootStrap, forms.Form):
    pass
    """
           # def __init__(self, *args, **kwargs):
           #     super().__init__(*args, **kwargs)
           #
           #     # 循环找到所有的插件，添加了class="form-control"
           #     for name, field in self.fields.items():
           #         # if name == "password":
           #         #     continue
           #         if field.widget.attrs:
           #             field.widget.attrs["class"] = "form-control"
           #             field.widget.attrs["placeholder"] = field.label
           #         else:
           #             field.widget.attrs = {
           #                 "class ": "form-control",
           #                 "placeholder": field.label
           #             }
       """
